package br.com.pixt;

import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;


import android.widget.TabHost;

public class Menu  extends TabActivity 
{
	private DataHelper bdh;

	public TabHost tabHost;
	@Override
	public void onCreate(Bundle bundle) {

		super.onCreate(bundle);
        
		this.tabHost = getTabHost();
        Bundle params ;
		Intent itParam = getIntent();
		String strCelNumber=null;
		String strCelDDD=null;
		
		Intent itTabCadastro = new Intent().setClass(this, TabCadastro.class);
		Intent itTabConsulta = new Intent().setClass(this, TabConsulta.class);
		int intQtdeHorasAbertas = 0;
		
		if (itParam!=null)
		{
	
			params = itParam.getExtras();
			intQtdeHorasAbertas = params.getInt("IntQtdeHorasAbertas");
			TelephonyManager telephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); 
			strCelDDD = params.getString("StrDDD");
			
			if (telephony.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) 
			{ 
				strCelNumber =telephony.getLine1Number();
			} 
			if (telephony.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) 
			{ 
				strCelNumber =telephony.getLine1Number();
			} 

		
			this.bdh = new DataHelper(this);
	        this.bdh.deleteAll();
			this.bdh.insert(params.getInt("IdCliente"),0,0,0,strCelDDD, strCelNumber,"");
//			List names = bdh.selectAll();
			itTabCadastro.putExtras(params);
		}
        
		if (intQtdeHorasAbertas == 0)
		{		
	        this.tabHost.addTab(this.tabHost.newTabSpec("TAB_CADASTRO").setIndicator("Comprar").setContent(itTabCadastro));
	        this.tabHost.addTab(this.tabHost.newTabSpec("TAB_CONSULTAR").setIndicator("Consulta").setContent(itTabConsulta));
		}
		else			
		{
	        this.tabHost.addTab(this.tabHost.newTabSpec("TAB_CONSULTAR").setIndicator("Consulta").setContent(itTabConsulta));
	        this.tabHost.addTab(this.tabHost.newTabSpec("TAB_CADASTRO").setIndicator("Comprar").setContent(itTabCadastro));
		}

		this.tabHost.setCurrentTab(0);  
		
		
	}
}
